package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.ProjectBonusConfig;
import com.ruoyi.erp.service.IProjectBonusConfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 提成比例配置Controller
 * 
 * @author sauger
 * @date 2022-04-22
 */
@Controller
@RequestMapping("/erp/staffingBonusConfig")
public class ProjectBonusConfigController extends BaseController
{
    private String prefix = "erp/staffingBonusConfig";

    @Autowired
    private IProjectBonusConfigService projectBonusConfigService;

    @RequiresPermissions("erp:staffingBonusConfig:view")
    @GetMapping()
    public String staffingBonusConfig()
    {
        return prefix + "/staffingBonusConfig";
    }

    /**
     * 查询提成比例配置列表
     */
    @RequiresPermissions("erp:staffingBonusConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectBonusConfig projectBonusConfig)
    {
        startPage();
        List<ProjectBonusConfig> list = projectBonusConfigService.selectProjectBonusConfigList(projectBonusConfig);
        return getDataTable(list);
    }

    /**
     * 导出提成比例配置列表
     */
    @RequiresPermissions("erp:staffingBonusConfig:export")
    @Log(title = "提成比例配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectBonusConfig projectBonusConfig)
    {
        List<ProjectBonusConfig> list = projectBonusConfigService.selectProjectBonusConfigList(projectBonusConfig);
        ExcelUtil<ProjectBonusConfig> util = new ExcelUtil<ProjectBonusConfig>(ProjectBonusConfig.class);
        return util.exportExcel(list, "提成比例配置数据");
    }

    /**
     * 新增提成比例配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存提成比例配置
     */
    @RequiresPermissions("erp:staffingBonusConfig:add")
    @Log(title = "提成比例配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectBonusConfig projectBonusConfig)
    {
        return toAjax(projectBonusConfigService.insertProjectBonusConfig(projectBonusConfig));
    }

    /**
     * 修改提成比例配置
     */
    @RequiresPermissions("erp:staffingBonusConfig:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProjectBonusConfig projectBonusConfig = projectBonusConfigService.selectProjectBonusConfigById(id);
        mmap.put("projectBonusConfig", projectBonusConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存提成比例配置
     */
    @RequiresPermissions("erp:staffingBonusConfig:edit")
    @Log(title = "提成比例配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectBonusConfig projectBonusConfig)
    {
        return toAjax(projectBonusConfigService.updateProjectBonusConfig(projectBonusConfig));
    }

    /**
     * 删除提成比例配置
     */
    @RequiresPermissions("erp:staffingBonusConfig:remove")
    @Log(title = "提成比例配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(projectBonusConfigService.deleteProjectBonusConfigByIds(ids));
    }
}
